/*
 *所有关于new_overtime类的业务代码应在此处编写
*可使用repository.调用常用方法，获取EF/Dapper等信息
*如果需要事务请使用repository.DbContextBeginTransaction
*也可使用DBServerProvider.手动获取数据库相关信息
*用户信息、权限、角色等使用UserContext.Current操作
*new_overtimeService对增、删、改查、导入、导出、审核业务代码扩展参照ServiceFunFilter
*/
using VOL.Core.BaseProvider;
using VOL.Core.Extensions.AutofacManager;
using VOL.Entity.DomainModels;
using System.Linq;
using VOL.Core.Utilities;
using System.Linq.Expressions;
using VOL.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;
using VOL.Test.IRepositories;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
using static System.Net.Mime.MediaTypeNames;
using Application = Microsoft.Office.Interop.Excel.Application;
using Microsoft.Office.Interop.Excel;
using OfficeOpenXml;
using Range = Microsoft.Office.Interop.Excel.Range;
using System.Reflection;
using System;
using System.Data;
using DataTable = System.Data.DataTable;
using Microsoft.AspNetCore.Mvc;

namespace VOL.Test.Services
{
    public partial class new_overtimeService
    {
        private readonly IHttpContextAccessor _httpContextAccessor;
        private readonly Inew_overtimeRepository _repository;//访问数据库

        [ActivatorUtilitiesConstructor]
        public new_overtimeService(
            Inew_overtimeRepository dbRepository,
            IHttpContextAccessor httpContextAccessor
            )
        : base(dbRepository)
        {
            _httpContextAccessor = httpContextAccessor;
            _repository = dbRepository;
            //多租户会用到这init代码，其他情况可以不用
            //base.Init(dbRepository);
        }


        //2.在生成页面新建数据时生成自增单据号
        //重写[表Service.cs]的add方法，实现下面的代码
        public override WebResponseContent Add(SaveModel saveDataModel)
        {
            saveDataModel.MainData["OrderNo"] = "OT";
            WebResponseContent webResponse = new WebResponseContent();
            AddOnExecuting = (new_overtime order, object list) =>
            {
                /************每天从1开始生成自增单据号，参数说明**********/
                // x => x.OrderNo 给指定字段生成单据号
                // "PO" 自定义单据号开头
                // x => x.CreateDate 指定日期字段,内部通过此字段排序，每天单据号从1开始
                order.new_name = order.Create(x => x.new_name, "PO", x => x.CreateDate);
                return webResponse.OK();
            };
            return base.Add(saveDataModel);
        }

        //public IActionResult ExportByTemptate(PageDataOptions pageData)
        //{
            
        //    return File(bytes, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "加班申请明细_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx");
        //}
    }
}
